/**
 * JzSmsService.java 
 * Copyright © 2009-2014, Liu Tao
 * 
 * @author Liu Tao
 * @create 2015年1月11日
 */
package com.pshare.msg.sms.service.impl;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;


//import com.jianzhou.sdk.BusinessService;
import com.pshare.framework.validator.TelephoneValidator;
import com.pshare.msg.sms.service.SmsService;
import com.pshare.util.SysPropertyUtils;

/**
 * 建周短信接口
 */
@Service("jzSmsService")
public class JzSmsService extends SmsService {
	
	private static final Logger logger = Logger.getLogger(JzSmsService.class);
	
	private static final String URL = SysPropertyUtils.getProperty("sms.access.url");
	private static final String account = SysPropertyUtils.getProperty("sms.key");
	private static final String password = SysPropertyUtils.getProperty("sms.pwd");
	private static final String SIGNATURE = "【" + SysPropertyUtils.getProperty("sms.signature") + "】";
//	private static BusinessService bs = new BusinessService();
	
	static {
//		bs.setWebService(URL);
	}
	
	@Override
	public synchronized void send(String cellphone, String message) {
		if (!TelephoneValidator.isCellphone(cellphone)) {
			logger.warn("cellphone is invalid: " + cellphone);
			return;
		}
		// 防止骚扰
		if (!allowSend(cellphone)) {
			logger.warn("not allowed send sms to cellphone " + cellphone + " in 10 minutes");
			return;
		}
		
		try {
			logger.info("begin to send sms to " + cellphone);
			logger.info("短信信息为："+ message);
//			int result = bs.sendBatchMessage(account, password, cellphone, message + suffix);
//			logger.info("send sms result: " + result);
			logger.info("complete sending sms to " + cellphone);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}
	
}
